package br.com.academia.controller;

import java.sql.SQLException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import br.com.academia.DAO.DAOGenerico;
import br.com.academia.beans.Exercicio;
import br.com.academia.util.ConnectionFactory;

@Controller
public class ExercicioController {
	
	@RequestMapping("/inserirExercicio")
	public String cadastrarExercicio(Exercicio exercicio) throws SQLException, Exception {
		new DAOGenerico<Exercicio>(new ConnectionFactory().getConnection()).cadastrar(exercicio);
		return "redirect:frmExercicio";
	}
	
	@RequestMapping("/alterarExercicio")
	public String alterarExercicio(Exercicio exercicio) throws SQLException, Exception {
		new DAOGenerico<Exercicio>(new ConnectionFactory().getConnection()).alterar(exercicio, "idExercicio");
		return "forward:pesquisaAvancada?tipoPesquisa=exercicio";
	}
	
	@RequestMapping("/excluirExercicio")
	public String excluirExercicio(Exercicio exercicio) throws SQLException, Exception {
		new DAOGenerico<Exercicio>(new ConnectionFactory().getConnection()).excluir(exercicio, "idExercicio");
		return "forward:pesquisaAvancada?tipoPesquisa=exercicio";
	}


}
